module D{
    export class UserData extends PlayerData implements NetMessage{
        /** 账号 */
        public account:string;
        /** 机器码 */
        public machine:string;
        /** 密码 */
        public password:string;

        /** 接收到消息 */
        public onMessage(d:any):void{
            switch(d[1]){
                case 100:{ //登陆完成
                    this.loginSuccess(d[2]);
                    break;
                }case 101:{ //登陆失败
                    if(d[2].lErrorCode == 217){ //账号未注册
                        D.App.net.send('[1,3,{"dwPlazaVersion":100000,"szAccounts":"'+this.account+'","szPassWord":"'+this.password+'","wFaceID":'+Math.floor(Math.random()*10)+',"cbGender":'+Math.floor(Math.random())+',"szSpreader":0,"szNickName":"N'+this.account.substr(0, 8)+'","szComputerID":"'+this.machine+'"}]');
                    }
                    break;
                }case 102:{ //登陆结束
                    App.stage.removeChildren();
                    App.showMain();
                    break;
                }
            }
        }

        /** 登录 */
        public async login(){
            let u = await platform.getUserInfo();
            this.account = u.account;
            this.password = u.password;
            this.machine = u.machine;
            await platform.login();
            D.App.net.send('[1,11,{"ChannelID":100000,"szAccounts":"'+D.App.userData.account+'","szPassWord":"'+D.App.userData.password+'","machineSerial":"'+D.App.userData.machine+'"}]');
        }

        /** 登录成功返回的消息 */
        public loginSuccess(d:any):void{
            this.gameScore = Number(d.dwFortuneCoin);
            this.account = d.accounts;

            this.userID = d.dwUserID;
            this.nickName = d.nickname;
            this.faceID = d.wFaceID;
            this.gender = d.cbGender;
        }
    }
}